<?php
/**
 * Created by PhpStorm.
 * User: 1
 * Date: 2018/3/5
 * Time: 16:25
 */

namespace app\admin\model;


use think\Model;

class TeacherStopLesson extends Model
{
    /**
     * 获取所有教师发布停课信息
     * @author 巫玉梅 <1120504614@qq.com>
     * @return
     */
    public function getAll(){
        $order="";
        $keywords   = trim(input('get.keywords'));
        if(!empty($keywords)){
            $where = ['us.full_name|us.tel|us.username'=> ['like', "%{$keywords}%"]];
        }else{
            $where = [];
        }
        $data = $this
            ->alias('t')
            ->join('lesson le','t.les_id = le.id','LEFT')
            ->join('user us','t.t_id = us.id','LEFT') //获取教师姓名
            ->join('user user','t.stu_stop_id = user.id','LEFT')
            ->field('t.*,t.les_id,le.lesson_sn,le.lesson_name,
                    us.full_name as teacher_name,user.full_name as student_name,
                    t.t_stop_content,t.t_stop_status')
            ->where($where)
            ->select();
        if($data){
            foreach($data as $k => $v){
                $data[$k] = $v->toArray();
            }
        }

        return $data;
    }

    /**
     * 获取所有停课记录数
     * @author 巫玉梅 <1120504614@qq.com>
     * @return
     */
    public function getCount(){
        $order="";
        $keywords   = trim(input('get.keywords'));
        if(!empty($keywords)){
            $where = ['us.full_name|us.tel|us.username'=> ['like', "%{$keywords}%"]];
        }else{
            $where = [];
        }
        $count = $this
            ->alias('t')
            ->join('lesson le','t.les_id = le.id','LEFT')
            ->join('user us','t.t_id = us.id','LEFT') //获取教师姓名
            ->join('user user','t.stu_stop_id = user.id','LEFT')
            ->field('t.*,t.les_id,le.lesson_sn,le.lesson_name,
                    us.full_name as teacher_name,user.full_name as student_name,
                    t.t_stop_content,t.t_stop_status')
            ->where($where)
            ->count();
        return $count;
    }

    /**
     * 查询单条信息
     * @author 巫玉梅 <1120504614@qq.com>
     * @return
     */
    public function getOne($where=""){
        $info = $this
            ->alias('t')
            ->join('lesson le','t.les_id = le.id','LEFT')
            ->join('user us','t.t_id = us.id','LEFT') //获取教师姓名
            ->join('user user','t.stu_stop_id = user.id','LEFT')
            ->field('t.*,t.les_id,le.lesson_sn,le.lesson_name,
                    us.full_name as teacher_name,user.full_name as student_name,
                    t.t_stop_content,t.t_stop_status')
            ->where($where)
            ->find();
            if($info){
                $info = $info -> toArray();
            }
        return $info;
    }
}